import tseslint from 'typescript-eslint'

import * as importPlugin from 'eslint-plugin-import-x'
import { renamePluginsInRules } from 'eslint-flat-config-utils'
import { FlatConfig, OptionsOverrides } from '../types'

export default async ({ overrides = {} }: OptionsOverrides = {}): Promise<FlatConfig[]> => {
  return [
    {
      ...(tseslint.configs.base as any),
      name: 'vill-v/typescript/base',
    },
    {
      ...tseslint.configs.eslintRecommended,
      name: 'vill-v/typescript/rules',
      files: ['**/*.?([cm])[jt]s?(x)'],
      rules: {
        ...tseslint.configs.eslintRecommended.rules,
        '@typescript-eslint/explicit-module-boundary-types': 'off',
        '@typescript-eslint/no-explicit-any': 'off',
        'no-unused-vars': 'off',
        '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
        ...overrides,
      },
    },
    {
      name: 'vill-v/typescript/js-rules',
      files: ['**/*.?([cm])js?(x)'],
      rules: {
        '@typescript-eslint/no-require-imports': 'off',
        ...overrides,
      },
    },
    {
      name: 'vill-v/typescript/imports',
      settings: renamePluginsInRules(importPlugin.configs.typescript.settings, {
        'import-x': 'import',
      }),
      rules: renamePluginsInRules(importPlugin.configs.typescript.rules, { 'import-x': 'import' }),
    },
  ]
}
